package edu.ihs.lhpy.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;

import edu.ihs.lhpy.base.BaseAction;
import edu.ihs.lhpy.domain.PageBean;
import edu.ihs.lhpy.domain.WorkGuide;
@Controller
@Scope("prototype")
public class WorkGuideAction extends BaseAction<WorkGuide>{

	//列表
	public String list() throws Exception{
		PageBean pageBean = workGuideService.getPageBean(pageNum);
		ActionContext.getContext().getValueStack().push(pageBean);
		return "list";
	}
	//添加
	public String add() throws Exception{
		workGuideService.save(model);
		//添加成功
		addFieldError("addsuccess","修改成功");
		return "toList";
	}
	//添加界面
	public String addUI() throws Exception{
		return "saveUI";
	}
	//删除
	public String delete() throws Exception{
		workGuideService.delete(model.getId());
		//删除成功
		addFieldError("deletesuccess","修改成功");
		return "toList";
	}
	//修改
	public String edit() throws Exception{
		WorkGuide workGuide = workGuideService.getById(model.getId());
		
		workGuide.setAuthor(model.getAuthor());
		workGuide.setContent(model.getContent());
		workGuide.setTime(model.getTime());
		workGuide.setTitle(model.getTitle());
		
		//更新到数据库中
		workGuideService.update(workGuide);
		//修改成功
		addFieldError("editsuccess","修改成功");
		return "toList";
	}
	//修改界面
	public String editUI() throws Exception{
		//准备回显数据
		WorkGuide workGuide = workGuideService.getById(model.getId());
		ActionContext.getContext().getValueStack().push(workGuide);
		return "saveUI";
	}
	
	
}
